home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1997 December: Technology Seed / ATS Dec. '97.toast / Navigation Services SDK 1.0b1 / Examples / Sampler / Sampler ƒ / Common.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-11-20  |  8.4 KB  |  334 lines  |  [TEXT/MPS ]

  1. /*
  2.     File:        Common.h
  3.  
  4.     Copyright:    © 1997 by Apple Computer, Inc., all rights reserved.
  5.  
  6. */
  7.  
  8. #ifndef __TYPES__
  9. #include <Types.h>
  10. #endif
  11.  
  12. #ifndef __DIALOGS__
  13. #include <Dialogs.h>
  14. #endif
  15.  
  16. #ifndef __LOWMEM__
  17. #include <LowMem.h>
  18. #endif
  19.  
  20. #ifndef __TEXTUTILS__
  21. #include <TextUtils.h>
  22. #endif
  23.  
  24. #ifndef __PRINTING__
  25. #include <Printing.h>
  26. #endif
  27.  
  28. #ifndef __APPLEEVENTS__
  29. #include <AppleEvents.h>
  30. #endif
  31.  
  32. #ifndef __QDOFFSCREEN__
  33. #include <QDOffscreen.h>
  34. #endif
  35.  
  36. #include "Navigation.h"
  37.  
  38. #ifndef Common_Defs
  39. #define Common_Defs
  40.  
  41. #define kStr255Len            255        // this length is for NewPtr call, used before making a Toolbox call
  42. #define kNameLen            32        // file name length
  43.  
  44. enum checkboxstate { dechecked,checked };
  45.  
  46. #define kStrangeErr            -1
  47.  
  48. #define kActive                0
  49. #define kInactive            255
  50.  
  51. // ASCII key characters
  52. #define kCrChar                    13        // carriage return key 
  53. #define kDelChar                8        // delete key 
  54. #define kEnterChar                3        // enter char 
  55. #define kPeriodChar                46        // period char 
  56. #define kTabKey                    9        // tab char 
  57. #define kYKey                    121
  58. #define kNKey                    110
  59. #define kEscKey                    27
  60. #define kColon                    58
  61. #define kZero                    48
  62. #define kNine                    57
  63.  
  64. #define    dOK                        1
  65. #define dCancel                    2
  66.  
  67. #define kDelayTick                10        // ticks for button hiliting
  68. #define kWindowWidth            500        // width size for the text window
  69.  
  70. #define    kMaxDocumentCount        100        // maximum number of documents allowed
  71.  
  72. #define    InitialH                16
  73. #define    InitialV                42
  74.  
  75. #define    TopMargin                6
  76. #define    LeftMargin                6
  77. #define    RightMargin                6
  78. #define    BottomMargin            6
  79.  
  80. #define    ScrollResolution        12
  81.  
  82. #define kOpenRsrcID                300
  83.  
  84. // file constants
  85. #define    kFileCreator            'CPAP'
  86. #define    kFileType                'TEXT'
  87. #define kFileTypePICT            'PICT'
  88. #define kOpenRsrcType            'open'
  89.  
  90. // resource constants
  91. #define rIconSuite                128
  92.  
  93. #define iIconSuite                3
  94.  
  95. // alert resources constants:
  96. #define rSaveChangesID            128
  97. #define rRevertID                129
  98. #define rGenericAlertID            130
  99. #define rAboutID                131
  100.  
  101. // resource string constants
  102. #define    rAppStringsID            128
  103. enum {
  104.     sApplicationName = 1,
  105.     sTranslationLockedErr,
  106.     sTranslationErr,
  107.     sOpeningErr,
  108.     sReadErr,
  109.     sWriteToBusyFileErr,
  110.     sBusyOpen,
  111.     sChooseFile,
  112.     sChooseFolder,
  113.     sChooseVolume,
  114.     sCreateFolder,
  115.     sChooseObject,
  116.     sSaveCopyMessage,
  117.     slSavePromptIndex,
  118.     slClosingIndex,
  119.     slQuittingIndex
  120. };
  121.  
  122. #define    MenuStringsID            129
  123. enum {
  124.     slCantUndo = 1,
  125.     slUndoDrag,
  126.     slRedoDrag
  127. };
  128.  
  129. // menu resource constants
  130. #define    MenuBarID                128
  131.  
  132. #define    idAppleMenu                128
  133. #define    AboutItem                1
  134.  
  135. #define    idFileMenu                129
  136. #define    NewItem                    1
  137. #define    OpenItem                2
  138. #define    CloseItem                4
  139. #define    SaveItem                5
  140. #define SaveACopyItem            6
  141. #define    RevertItem                7
  142. //=
  143. #define DictionaryItem            9
  144. //=
  145. #define    PageSetupItem            11
  146. #define    PrintItem                12
  147. //=
  148. #define    QuitItem                14
  149.  
  150. #define    idEditMenu                130
  151. #define    iUndo                    1
  152. #define    iCut                    3
  153. #define    iCopy                    4
  154. #define    iPaste                    5
  155. #define    iClear                    6
  156. #define    iSelectAll                7
  157.  
  158. #define idUtilsMenu                131
  159. #define iSelectDir                1
  160. #define iSelectVol                2
  161. #define iSelectObject            3
  162. #define iCreateFolder            5
  163. #define iCustomOpen                7
  164.  
  165. #define kScrollBarWidth         16
  166. #define kScrollBarPos             kScrollBarWidth-1
  167.  
  168. // main document:
  169. typedef struct Document
  170. {
  171.     WindowPtr        theWindow;
  172.     TEHandle        theTE;
  173.     short            docTop;
  174.     RgnHandle        hiliteRgn;
  175.     
  176.     ControlHandle    vScroll;
  177.     ControlHandle    hScroll;
  178.     short            vScrollPos;
  179.     
  180.     short            fRefNum;
  181.     short            dirty;
  182.     
  183.     Handle            undoDragText;
  184.     short            undoSelStart;
  185.     short            undoSelEnd;
  186.     
  187.     short            lastSelStart;
  188.     short            lastSelEnd;
  189.  
  190.     ParamBlockRec    fioParamBlock;            // param block for file I/O operations
  191.     Handle            fPict;
  192.     Handle            fHeader;
  193.     long            fPictLength;
  194.  
  195. } Document;
  196.  
  197.  
  198. // offscreen drawing:
  199. typedef struct WindowOffscreen
  200. {
  201.     CGrafPtr        windowPort;
  202.     GDHandle        windowDevice;
  203.     GWorldPtr        offscreenWorld;
  204. } WindowOffscreen;
  205.  
  206. WindowOffscreen* DrawOffscreen(WindowPtr theWindow);
  207.  
  208.  
  209. #define mBarHeight    (short *)0x0BAA        // Low mem global for menu bar
  210. #define EventQueue  (QHdrPtr)0x14A         // Event queue header (10 bytes)
  211. #define Mouse        ((Point*)0x830)        // processed mouse
  212. #define KeyTime     (long*)0x186        // tickcount when KEYLAST was rec'd 
  213.  
  214. #define TopLeft(aRect)    (* (Point *) &(aRect).top)
  215. #define BotRight(aRect)    (* (Point *) &(aRect).bottom)
  216.  
  217. #define RectWidth(aRect) ((aRect).right - (aRect).left)
  218. #define RectHeight(aRect) ((aRect).bottom - (aRect).top)
  219.  
  220. #define Max(X, Y) ( ((X)>(Y)) ? (X) : (Y) )
  221. #define Min(X, Y) (  ((X)>(Y)) ? (Y) : (X) )
  222.  
  223. #define Pin(VALUE, MIN, MAX) ( ((VALUE) < (MIN)) ? (MIN) : ( ((VALUE) > (MAX)) ? (MAX) : (VALUE) ) )
  224.  
  225. #define kOpenPrefKey            1
  226. #define kSavePrefKey            2
  227. #define kSelectFilePrefKey        3
  228. #define kSelectFolderPrefKey    4
  229. #define kSelectVolumePrefKey    5
  230. #define kNewFolderPrefKey        6
  231. #define kSelectObjectPrefKey    7
  232.         
  233. //**************************************************************
  234.  
  235. // utility routines for detecting keydowns
  236. Boolean ModifierDown(short modifier);
  237. Boolean OptionDown(void);
  238. Boolean ShiftDown(void);
  239. Boolean CommandDown(void);
  240. Boolean ControlDown(void);
  241.  
  242. static SInt16 rnd(SInt16 max);
  243. short RandTween(short low, short high);
  244.  
  245. // file utilities:
  246. OSErr PathNameFromDirID(long dirID, short vRefNum, StringPtr fullPathName, short maxPathLength, short full);
  247. Boolean FSSpecsEq(FSSpec* a, FSSpec* b);
  248. pascal void myEventProc(NavEventCallbackMessage callBackSelctor, NavCBRecPtr callBackParms, NavCallBackUserData callBackUD);
  249.  
  250. // dialog control utilities
  251. void hiliteTheButton(DialogPtr theDialog, short whichItem);
  252. void AdornButton(DialogPtr theDialog, short whichItem);
  253. unsigned char* GetItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  254. void PokeItemStr(DialogPtr theDialog, short theItem, unsigned char* theString);
  255. void PokeCtlVal(DialogPtr theDialog, short theItem, short value);
  256. void PokeCtlHilite(DialogPtr theDialog, short theItem, short value);
  257.  
  258. // string utilities
  259. OSType Str2OSType(Str255 theStr);
  260. long MyStrLen(char* s);
  261. long myStringToLong(char* s);
  262. short myStringToShort(char* s);
  263. void myStrCpy(char* dst, char* src);
  264. void myStrCat(char* dst, char* src);
  265. unsigned char* ConcatPP(unsigned char* a,unsigned char* b);
  266. char* MyP2CCopy(unsigned char* psrc,char* ctarget);
  267. unsigned char* MyC2PStr(char* theStr);
  268. char* MyP2CStr(unsigned char* theStr);
  269.  
  270. void DrawIconSuite(short resID, Rect destRect);
  271. void DebugCStr(char* msg);
  272. void AdjustCursor(Point theLoc, RgnHandle theRgn);
  273.  
  274.  
  275. // *******************************************************************
  276.  
  277. // prototypes for 'document.c'
  278. Document* NewDocument(Boolean newAsPICT);
  279. Document* IsDocumentWindow(WindowPtr theWindow);
  280. void DoUndoDrag(void);
  281. pascal void DocumentClickLoop(void);
  282. void DoActivateDocument(Document* theDocument, short activate);
  283. void DoSelectAllDocument(Document* theDocument);
  284. void UpdateWindow(Document* theDocument);
  285. void GrowDocumentWindow(WindowPtr theWindow, Point thePoint);
  286. void DoZoomDocument(Document* theDocument, WindowPtr theWindow, short thePart);
  287. pascal void ScrollProc(ControlHandle theControl, short theCode);
  288. void DocumentHighlightProc(void);
  289. void SizeDocWindow(Document* theDocument);
  290.  
  291. // prototypes for 'files.c'
  292. short DoSaveDocument(Document* theDocument);
  293. void DoNewDocument(Boolean newDocAsPICT);
  294. OSErr DoOpenFile(FSSpec* theFile, Boolean openAsPICT);
  295.  
  296. OSErr DoOpenDocument(void);
  297. OSErr DoOpenDocumentTheOldWay(void);
  298.  
  299. OSErr SaveACopyDocument(Document* theDocument);
  300. OSErr SaveACopyDocumentTheOldWay(Document* theDocument);
  301.  
  302. void DoRevertDocument(Document* theDocument);
  303. void DoRevertDocumentTheOldWay(Document* theDocument);
  304.  
  305. // prototypes for 'Utilities.c'
  306. short TEIsFrontOfLine(short offset, TEHandle theTE);
  307. short TEGetLine(short offset, TEHandle theTE);
  308. short myTECut(TEHandle theTE);
  309. short myTEPaste(TEHandle theTE, short* spaceBefore, short* spaceAfter);
  310.  
  311. // prototypes for 'Offscreen.c'
  312. void DrawOnscreen(WindowOffscreen* theOffscreen);
  313.  
  314. // prototypes for 'document.c'
  315. void AdjustDocumentView(Document* theDocument);
  316. void AdjustScrollBar(Document* theDocument);
  317. void CloseDocument(Document* theDocument, Boolean quitting);
  318. void DisableUndoDrag(void);
  319. void AddText(Document* theDocument, Ptr text, long len);
  320.  
  321. // prototypes for 'drag.c'
  322. short DragText(Document* theDocument, EventRecord* theEvent, RgnHandle hiliteRgn);
  323.  
  324. // prototypes for 'menu.c'
  325. void AdjustMenus(void);
  326. void DoMenuCommand(long select);
  327.  
  328. // prototypes for 'event.c'
  329. void EventLoop(void);
  330. pascal OSErr MyHandleOAPP(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  331. pascal OSErr MyHandleODOC(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  332. pascal OSErr MyHandleQUIT(AppleEvent* theAppleEvent, AppleEvent* reply, long handlerRefCon);
  333.  
  334. #endif // Common_Defs